package com.market.service.admin.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.market.bean.MarketFeedback;
import com.market.bean.MarketFeedbackExample;
import com.market.bean.common.BasePageInfo;
import com.market.bean.common.CommonData;
import com.market.mapper.MarketFeedbackMapper;
import com.market.service.admin.AdminFeedbackService;
import com.market.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tan
 * @date 2022年12月29日 17:57
 */
@Service
public class AdminFeedbackServiceImpl implements AdminFeedbackService {
    @Autowired
    MarketFeedbackMapper feedbackMapper;

    @Override
    public CommonData<MarketFeedback> list(BasePageInfo info, Integer id, String username) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        MarketFeedbackExample example = new MarketFeedbackExample();
        //排序
        example.setOrderByClause(info.getSort() + " " + info.getOrder());
        MarketFeedbackExample.Criteria criteria = example.createCriteria();
        //判空 增加if之后成为条件查询
        if (!StringUtil.isEmpty(username)) {
            criteria.andUsernameLike("%" + username + "%");
        }
        if (id != null) {
            criteria.andIdEqualTo(id);
        }
        criteria.andDeletedEqualTo(false);
        List<MarketFeedback> list = feedbackMapper.selectByExample(example);
        PageInfo<MarketFeedback> pageInfo = new PageInfo<>(list);
        return CommonData.data(pageInfo);
    }
}
